package com.whmnx.my.ui.viewmodel;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.whmnx.base.bean.OrderListBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.my.ui.fragment.MyOrderDetailsFragment;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * author : huang
 * date   : 2020/10/20 0020 12:01
 * version: 1.0
 * @author Administrator
 */
public class OrderItemViewModel3 extends ItemViewModel {
    public ObservableField<String> Product_Name = new ObservableField<>("");
    public ObservableField<String> Product_Price = new ObservableField<>("");
    public ObservableField<String> Product_Num = new ObservableField<>("");
    public ObservableField<String> Product_SPEC = new ObservableField<>("");

    public String imgUrl;
    private String order_id;

    public OrderItemViewModel3(@NonNull BaseViewModel viewModel, OrderListBean.ProductListBean productListBean, String order_id) {
        super(viewModel);
        this.order_id = order_id;
        Product_Name.set(productListBean.getProduct_Name());
        Product_Price.set("￥" + productListBean.getProduct_Price());
        Product_Num.set("x" + productListBean.getProduct_Num());
        Product_SPEC.set("规格: " + productListBean.getProduct_SPEC());

        if (!TextUtils.isEmpty(productListBean.getProduct_Image())){
            String[] split = productListBean.getProduct_Image().split(",");
            String url = split[0];
            this.imgUrl = url.contains(Constants.HOST) ? url : Constants.HOST + url;
        }
    }

    //订单详情
    public BindingCommand OnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            //订单号
            bundle.putString("Order_Id",order_id);
            viewModel.startContainerActivity(MyOrderDetailsFragment.class.getCanonicalName(),bundle);
        }
    });
}
